package cloud.lysky.java.on.concurrent.thread;

/**
 * @author luoly
 * @describe
 * @date 2022-10-18 18:44
 **/
public class ThreadInterruptTest {

    static int i = 0;
    public static void main(String[] args) {
        System.out.println("begin");
        Thread thread  = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    i++;
                    System.out.println(i);
                    //Thread.interrupted():清除中断标志位 false = false
                    //Thread.currentThread().isInterrupted():不会清除中断标志位
                    if (Thread.interrupted()){
                        System.out.println("Thread attempt interrupting!");
                    }

                    if (i == 10){
                        break;
                    }

                }
            }
        });
        //启动线程
        thread.start();
        //不会停止线程,只会设置一个中断标志位 flag=true
        thread.interrupt();
    }
}